{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ce26422-856c-4d00-b3af-b7137d582878",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Goes with the buildPayloadsAndWrappers.yml file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c62482f1-1746-4fd8-93b0-ac372bd4d58d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from mythic import mythic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb8917af-aa58-4201-ae84-f2cef41f0e53",
   "metadata": {},
   "outputs": [],
   "source": [
    "mythic_instance = await mythic.login(\n",
    "        username=\"mythic_admin\",\n",
    "        password=\"mythic_password\",\n",
    "        server_ip=\"mythic_nginx\",\n",
    "        server_port=7443,\n",
    "        timeout=-1\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b70af39-ca9c-4164-acba-bc927a39ee03",
   "metadata": {},
   "outputs": [],
   "source": [
    "### trigger: manual\n",
    "# This can only be triggered through the UI or via Scripting\n",
    "search_for_workflow = \"\"\"\n",
    "query FindWorkflows($name: String!) {\n",
    "  eventgroup(where: {name: {_eq: $name}, active: {_eq: true}, deleted: {_eq: false}, approved_to_run: {_eq: true}}) {\n",
    "    id\n",
    "  }\n",
    "}\n",
    "\"\"\"\n",
    "workflows = await mythic.execute_custom_query(\n",
    "    mythic=mythic_instance,\n",
    "    query=search_for_workflow,\n",
    "    variables={\"name\": \"generate apollo payloads\"}\n",
    ")\n",
    "print(workflows)\n",
    "for workflow in workflows[\"eventgroup\"]:\n",
    "    triggered = await mythic.execute_custom_query(\n",
    "        mythic=mythic_instance,\n",
    "        query=\"\"\"\n",
    "        mutation TriggerWorkflowManually($eventgroup_id: Int!){\n",
    "            eventingTriggerManual(eventgroup_id: $eventgroup_id){\n",
    "                status\n",
    "                error\n",
    "            }\n",
    "        }\n",
    "        \"\"\",\n",
    "        variables={\"eventgroup_id\": workflow[\"id\"]}\n",
    "    )\n",
    "    print(triggered)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8698de55-5b66-455a-b983-948627e40a34",
   "metadata": {},
   "outputs": [],
   "source": [
    "### action: payload_create (normal egress payload)\n",
    "#  - name: \"apollo bin\"\n",
    "#    description: \"generate shellcode\"\n",
    "#    action: \"payload_create\"\n",
    "#    action_data:\n",
    "#      payload_type: \"apollo\" <-- identify the payload type\n",
    "#      description: \"apollo test payload shellcode\"\n",
    "#      selected_os: \"Windows\" <-- identify the operating system version\n",
    "#      build_parameters: <-- specify build parameters with name and values, an array of dictionaries\n",
    "#      - name: \"output_type\"\n",
    "#        value: \"Shellcode\"\n",
    "#      filename: \"apollo.bin\"\n",
    "#      c2_profiles: <-- specify c2 profiles as an array of dictionaries\n",
    "#      - c2_profile: \"websocket\"\n",
    "#        c2_profile_parameters: <-- for each profile, specify all the values you want to specify, otherwise defaults will be used\n",
    "#          AESPSK: \"aes256_hmac\"\n",
    "#          callback_host: \"ws://192.168.0.118\"\n",
    "#          tasking_type: \"Push\"\n",
    "#      commands: <-- identify any commands you want included\n",
    "#      - shell\n",
    "#      - exit\n",
    "#      - load\n",
    "#    outputs: <-- identify what outputs you want from here\n",
    "#      PayloadUUID: \"uuid\" <-- because we created a payload, we have all of the payload's attriutes to pull from"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bd49ad1-bc48-41dd-9155-6674b1527eca",
   "metadata": {},
   "outputs": [],
   "source": [
    "payload_attribute_query = \"\"\"\n",
    "query MyQuery {\n",
    "  payload(limit: 1) {\n",
    "    apitokens_id\n",
    "    auto_generated\n",
    "    build_container\n",
    "    build_message\n",
    "    build_phase\n",
    "    build_stderr\n",
    "    build_stdout\n",
    "    callback_alert\n",
    "    creation_time\n",
    "    deleted\n",
    "    description\n",
    "    eventstepinstance_id\n",
    "    file_id\n",
    "    id\n",
    "    operation_id\n",
    "    operator_id\n",
    "    os\n",
    "    payload_type_id\n",
    "    task_id\n",
    "    timestamp\n",
    "    uuid\n",
    "    wrapped_payload_id\n",
    "  }\n",
    "}\n",
    "\"\"\"\n",
    "fields = await mythic.execute_custom_query(\n",
    "    mythic=mythic_instance,\n",
    "    query=payload_attribute_query\n",
    ")\n",
    "print(fields)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d93f7b8-8e0a-4e16-a9ac-01f189caee59",
   "metadata": {},
   "outputs": [],
   "source": [
    "## action: custom_function\n",
    "\n",
    "#- name: \"bin opsec checker\"\n",
    "#    description: \"check finished payloads for bad keywords\"\n",
    "#    action: \"custom_function\"\n",
    "#    depends_on:\n",
    "#    - \"apollo bin\" <-- only gets executed after the step named \"apollo bin\" finishes successfully\n",
    "#    inputs:\n",
    "#      PayloadUUID: \"apollo bin.PayloadUUID\" <-- save the named output from \"apollo bin\"\n",
    "#      APIToken: \"mythic.apitoken\" <-- ask Mythic for an APIToken for this step\n",
    "#    action_data:\n",
    "#      function_name: \"opsecStrings\" <-- function within container to execute\n",
    "#      container_name: \"fileProcessor\" <-- container to task"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da1970e1-a7c0-4c9a-b1ea-2f58c50cdd9c",
   "metadata": {},
   "outputs": [],
   "source": [
    "## action: conditional_check (potentially skip steps)\n",
    "\n",
    "# - name: \"conditional checker\"\n",
    "#    description: \"check for more things\"\n",
    "#    action: \"conditional_check\"\n",
    "#    depends_on:\n",
    "#    - \"bin opsec checker\" <-- this named step must happen first\n",
    "#    inputs:\n",
    "#      APIToken: \"mythic.apitoken\" <-- ask Mythic for a temporary APIToken for this step\n",
    "#      PayloadUUID: \"apollo bin.PayloadUUID\" <-- take as an input to this step the named output from the \"apollo bin\" step\n",
    "#    action_data:\n",
    "#      function_name: \"conditionalService\" <-- the name of the conditional function to execute\n",
    "#      container_name: \"fileProcessor\" <-- the name of the container that offers the above function\n",
    "#      steps:\n",
    "#        - \"apollo service\" <-- which step(s) we're deciding should be skipped or not"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de23d52b-7afc-487b-a83d-6eeb5e40bc75",
   "metadata": {},
   "outputs": [],
   "source": [
    "## action: payload_create\n",
    "\n",
    "#  - name: \"apollo service\"\n",
    "#    description: \"service exe with apollo shellcode\"\n",
    "#    action: \"payload_create\"\n",
    "#    inputs:\n",
    "#      WRAPPER_UUID: \"apollo bin.PayloadUUID\" <-- we're going to use the named output from \"apollo bin\" as an input to this step\n",
    "#    depends_on:\n",
    "#    - \"conditional checker\" <-- only execute this after this named step completed successfully\n",
    "#    action_data:\n",
    "#      payload_type: \"service_wrapper\" <-- name of the payload type we're going to use\n",
    "#      description: \"apollo service exe\"\n",
    "#      selected_os: \"Windows\"\n",
    "#      build_parameters:\n",
    "#      - name: \"version\"\n",
    "#        value: \"4.0\"\n",
    "#      - name: \"arch\"\n",
    "#        value: \"x64\"\n",
    "#      filename: \"apollo_service.exe\"\n",
    "#      wrapped_payload: WRAPPER_UUID <-- since this is a wrapper, we provide the UUID of the payload we're going to wrap\n",
    "#    outputs:\n",
    "#      PayloadUUID: \"uuid\" <-- we can output the new UUID for this wrapped payload"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
